package com.atguigu.paymentdemo.contoller;


import com.atguigu.paymentdemo.entity.Product;
import com.atguigu.paymentdemo.service.ProductService;
import com.atguigu.paymentdemo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@CrossOrigin //开发前端的跨域访问
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/test")
    public Result test(){
        //这里可以链式操作
        return Result.ok()
                .data("message","hello")
                .data("now",new Date());
    }
    @GetMapping("list")
    public Result list(){
        List<Product> list = productService.list();
        return Result.ok().data("productList",list);

    }

}
